@extends('layout.adminlayout')
@section('css')
<meta name="_token" content="{{ csrf_token() }}"/>
<script src="/admin/js/metisMenu.min.js"></script>
<script src="/admin/js/custom.js"></script>
<link href="/admin/css/custom.css" rel="stylesheet">
@endsection
@section('content')
<div class="tables">
	<div class="table-responsive bs-example widget-shadow">
		<h4 style="margin-bottom: 15px;">员工列表 :</h4>
		<form action="/admin/staff/index" method="get">
			<div class="row" style="padding-bottom: 15px;margin-top: 0px;">
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 70px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">代理商：</p>
				<select name="ag" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 15%;">
					<option value="">请选择代理商</option>
					@foreach($agent as $v)
						<option value="{{$v['id']}}"
								@if($get['ag'] == $v['id'])
								selected
								@else
								@if(Cookie::get('agentId') == $v['id'])
								selected
								@endif
								@endif>{!! $v['agent_name'] !!}</option>
					@endforeach
				</select>
				<p class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="width: 100px; height: 32px;padding: 0px;text-align: right;line-height: 32px;">员工名称：</p>
				<input type="text" name="linkman" id="" value="{{$get['linkman']}}" class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="height: 30px; line-height: 30px; padding: 0px; border: 1px solid #DDD; margin: 0px 10px; width: 15%;"/>
				<input type="submit" value="搜索" class="col-lg-1 col-md-1 col-sm-1 col-xs-1"  style="height: 30px; line-height: 32px; padding: 0px; border: 0; background: #4F52BA;width: 50px; margin: 0px 10px;color:#fff"/>	
			</div>
		</form>
		<table class="table table-bordered" >
			<thead>		
 				<tr>
					<th style="text-align: center">员工编号</th>
					<th style="text-align: center">员工账号</th>
					<th style="text-align: center">员工名称</th>
					<th style="text-align: center">手机号</th>
					<th style="text-align: center">权限</th>
					<th style="text-align: center">状态</th>
					@if($get['ag'] == Cookie::get('user')['agent_id'] || Cookie::get('user')['agent_id'] == 1)
					<th style="text-align: center">操作</th>
					@endif
					{{--@if($get['ag'] == Cookie::get('agentId'))
					<th style="text-align: center">操作</th>
					@endif--}}
				</tr>
			</thead>
			<tbody>
			@if(!null==$info)
				@foreach($info as $v)
					<tr> 
						<th scope="row" style="text-align: center">{{$v['id']}}</th>
						<td style="text-align: center">{{$v['account']}}</td>
						<td style="text-align: center">{{$v['linkman']}}</td>
						<td style="text-align: center">{{$v['phone']}}</td>
						<td style="text-align: center">
							@if($v['auth'] == 1)
								最高权限
							@else
								----
							@endif
						</td>
						<td style="text-align: center">@if(($v['id'] == 1||Cookie::get('user')['id']==$v['id'])&&$v['auth'] == 1)----@else<a href="javascript:void (0)" onclick="change({{$v['id']}})" id="state_{{$v['id']}}" value="{{$v['status']}}">@if($v['status'] == 1)禁用@else启用@endif</a>@endif</td>
						@if($get['ag'] == Cookie::get('user')['agent_id'] || Cookie::get('user')['agent_id'] == 1)
						<td style="text-align: center"><a href="/admin/staff/edit?uri={{$uri['uri']}}&id={{$v['id']}}">编辑</a></td>
						@endif
						{{--@if($get['ag'] == Cookie::get('agentId'))
						<td style="text-align: center"><a href="">编辑</a></td>
						@endif--}}
					</tr>
				@endforeach
			@endif
			</tbody> 
		</table>
		@if(!null == $data)
			<div style="float:right;">
				{!! $data->appends($request)->render() !!}
			</div>
		@endif
	</div>
</div>
<script>
	function change(id) {
		var status = $('#state_'+id).attr('value');
		$.ajax({
			type:'post',
			url:'/admin/staff/status',
            async:false,
            data:{
				id:id,
				status:status
			},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            },
            dataType:'json',
			success:function (data) {
					if(data.status == 1){
						$('#state_'+data.id).html('禁用')
					}else{
                        $('#state_'+data.id).html('启用')
					}
            }
		})
    }
</script>
@endsection